package demo.spring.boot.jdbc;

import demo.spring.boot.jdbc.repository.DepartmentRepository;
import demo.spring.boot.jdbc.repository.RoleRepository;
import demo.spring.boot.jdbc.repository.UserRepository;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * Created by lushun.chen on 2017/4/15.
 *
 * @author lushun.chen
 */
@Order(Ordered.HIGHEST_PRECEDENCE)
@Configuration
//启动jpa的事务管理
@ComponentScan
@EnableTransactionManagement(proxyTargetClass = true)
//启动jpa的资源库，并制定资源库的位置
@EnableJpaRepositories(basePackageClasses = {UserRepository.class, DepartmentRepository.class, RoleRepository.class})
//指定实体的位置
//@EntityScan(basePackageClasses = {User.class, Role.class, Department.class})
@EntityScan(basePackages = "demo.spring.boot.jdbc.**")
public class JpaConfig {

    public JpaConfig() {
    }

    @Bean
    public PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor() {
        return new PersistenceExceptionTranslationPostProcessor();
    }
}
